<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li {
            width: 120px;
            background-color: pink;
        }
        
        a {
            float: right;
        }
    </style>
</head>

<body>
    <textarea name="" id="" cols="30" rows="10"></textarea>
    <button>发布</button>
    <ul></ul>
    <script>
        var text = document.querySelector('textarea')
        var btn = document.querySelector('button')
        var ul = document.querySelector('ul')
        btn.onclick = function() {
            var textValue = text.value
            if (textValue.trim().length === 0) return alert('输入的值不能为空')
            var li = document.createElement('li')
            li.innerHTML = `${textValue} <a href='javascript:;' onclick='delLi(this)'>删除</a>`
            ul.appendChild(li)
            text.value = ''
        }
        function delLi(obj) {
            obj.parentNode.remove()
        }
    
    </script>
</body>

</html>